<%@ page language="java" isELIgnored="false"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Insert title here</title>
<!-- Bootstrap core CSS -->
<link href="/admin/public/bootstrap.min.css" title="" rel="stylesheet" />
<link href="/admin/font-awesome/css/font-awesome.min.css"
	rel="stylesheet" />
<link href="/admin/public/animate.css" rel="stylesheet" />
<link rel="stylesheet" href="/admin/public/inspinia.css" />
<link rel="stylesheet" href="/admin/css/pop-up.css" />
<link rel="stylesheet" href="/admin/css/plugins/toastr/toastr.min.css" />
<link rel="stylesheet" type="text/css"
	href="${request.getContext }/admin/css/xcConfirm.css" />
<script src="/admin/My97/WdatePicker.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
	<script src="/admin/public/html5shiv.min.js"></script>
	<script src="/admin/public/respond.min.js"></script>
<![endif]-->
</head>
<body>
	<div id="wrapper" class="container">
		<div class="wrapper wrapper-content">
			<div class="right_box">
				<div style="border: none; box-shadow: none;" class="right_one row">
					<div class="col-md-12 col-sm-12 col-xs-12" style="float: left;">
						<form class="form-horizontal" method="post" id="saveAdminUser"
							novalidate="novalidate">
							<div class="form-group">
								<label class="col-lg-2 control-label">用户名:</label>
								<div class="col-lg-6">
									<input type="text" class="form-control" id="userName"
										name="userName">
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">真实姓名:</label>
								<div class="col-lg-6">
									<input type="text" class="form-control" id="realname"
										name="realname">
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">密码:</label>
								<div class="col-lg-6">
									<input type="password" class="form-control" id="userPwd"
										name="userPwd">
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">电话:</label>
								<div class="col-lg-6">
									<input type="text" class="form-control" id="telenumber"
										name="telenumber" value="">
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">身份证号:</label>
								<div class="col-lg-6">
									<input type="text" class="form-control" id="identitynumber"
										name="identitynumber" value="">
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">所属角色:</label>
								<div class="col-lg-6">
									<c:forEach items="${role }" var="item">
										<input type="checkbox" style="width: 60px" id="roleId"
											value="${item.roleid }" name="roleId" />
										<span>${item.roleName }</span>
									</c:forEach>
								</div>
							</div>
							<input type="button" onclick="saveCustomer();" id="btnn"
								style="width: 82px; height: 34px; display: none; margin-left: 12px"
								value="保存" class="col-lg-3 btn btn-success" />
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script src="/admin/public/jquery-1.11.3.js"></script>
	<script src="/admin/public/bootstrap.min.js" type="text/javascript"></script>
	<script src="${request.getContext }/admin/js/xcConfirm.js"
		type="text/javascript" charset="utf-8"></script>
	<script src="/admin/js/plugins/toastr/toastr.min.js"></script>
	<script src="/admin/js/new_page.js"></script>
	<script>
		function check() {
			var userName = $("#userName").val();
			var realname = $("#realname").val();
			var userPwd = $("#userPwd").val();
			//var email=$("#email").val();
			var telenumber = $("#telenumber").val();
			//var identitynumber=$("#identitynumber").val();
			var roleIdlength = $("input[name='roleId']:checked").length;
			if (userName.length == 0) {
				alertNew('请输入用户名！', false);
				return false;
			}
			if (realname.length == 0) {
				alertNew('请输入真实姓名！', false);
				return false;
			}
			if (userPwd.length < 6) {
				alertNew('请输入大于6位数的密码！', false);
				return false;
			}
			if (telenumber.length != 11) {
				alertNew('请输入有效的手机号码位数！', false);
				return false;
			}
			var myreg = /^(((13[0-9]{1})|(14[4,7])|(15[0-9]{1})|(17[6-8]{1})|(18[0-9]{1}))+\d{8})$/; 
			if (!myreg.test(telenumber)) {
				alertNew('请输入有效的手机号码！', false);
				return false;
			}
			if (roleIdlength == 0) {
				alertNew('请选择角色！', false);
				return false;
			}
			return true;
		}
		function saveCustomer() {
			if (check()) {
				$.ajax({
					type : "post",
					data : $("#saveAdminUser").serialize(),
					dataType : "json",
					url : "/admin/user/addAdmin",
					success : function(data) {
						if (data.success) {
							alertNew(data.msg, true);
							$('#ifr', window.parent.document).attr('src',
									'/admin/user/adminlist');
						}
					},
					error : function(data) {
						alert("添加失败");
					}
				});
			}
		}
	</script>
</body>
</html>